﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Controls.Message
{
    [ToolboxItem(false)]
    public partial class WarningIcon : Control
    {
        private Color _borderColor;
        private Color _signalColor;
        private float _borderThickNess;

        [Browsable(true), Description("边框颜色")]
        [Category("Appearance")]
        public Color BorderColor
        {
            set { _borderColor = value; }
            get { return _borderColor; }
        }

        [Browsable(true),DefaultValue(4.0), Description("边框粗细")]
        [Category("Appearance")]
        public float BorderThickness
        {
            get { return _borderThickNess; }
            set { _borderThickNess = value;}
        }

        [Browsable(true),Description("感叹号颜色")]
        [Category("Appearance")]
        public Color SignalColor
        {
            get { return _signalColor; }
            set { _signalColor = value; }
        }

        public WarningIcon()
        {
            BorderColor = Color.FromArgb(249, 166, 38);
            BorderThickness = 4;
            SignalColor = Color.White;
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            var graphics = pe.Graphics;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            ///绘制三角形边框
            Pen pen = new Pen(BorderColor, BorderThickness);
            var pointFs = new PointF[3];
            pointFs[0] = new PointF(Width / 2 - 0.5f,  BorderThickness / 2);
            pointFs[1] = new PointF(BorderThickness / 2, Height - BorderThickness / 2);
            pointFs[2] = new PointF(Width - BorderThickness / 2 - 1, Height - BorderThickness / 2);
            graphics.DrawPolygon(pen, pointFs);
            
            ///填充三角形边框内部
            Brush brush = new SolidBrush(Color.FromArgb(243,129,4));
            graphics.FillPolygon(brush, pointFs);

            ///绘制感叹号
            Brush brushi = new SolidBrush(_signalColor);
            pointFs = new PointF[4];
            pointFs[0] = new PointF(this.Width / 2 - 2.5f, ((float)this.Height / 48) * 12f);
            pointFs[1] = new PointF(this.Width / 2 + 1.5f, ((float)this.Height / 48) * 12f);            
            pointFs[2] = new PointF(this.Width / 2 + 0.5f,this.Height - ((float)this.Height / 48) * 15);
            pointFs[3] = new PointF(this.Width / 2 - 1.5f, this.Height - ((float)this.Height / 48) * 15);

            graphics.FillPolygon(brushi, pointFs);
            ///感叹号的小圆圈
            graphics.FillEllipse(brushi, this.Width / 2 - 2.5f, this.Height - ((float)this.Height / 48) * 11.5f, 4, 4);
        }
    }
}
